<template>
  <div class="component-page">
    <h1 class="user-title">充币</h1>
    <div class="box">
      <p class="hint-text">币种选择</p>
      <el-select
        v-model="coin"
        placeholder="请选择"
        class="coin-select"
        @change="coinSelectChange(coin)"
      >
        <el-option
          v-for="item in otcCoinList"
          :key="item.value"
          :label="item.name"
          :value="item.id"
        ></el-option>
      </el-select>
    </div>
    <div class="box">
      <div class="chunk-box">
        <template>
          <p class="chunk-box-hint">链名称</p>
          <div class="support-box">
            <button
              v-for="(info,index) in item.ServerAddressInfo"
              :key="index"
              class="coin-btn cursor"
              :disabled="info.IsOpen*1==0"
              :class="info.IsOpen*1==0?'btnDis':(currentChain==info.ChannelName?'coinIsClick':'')"
              @click="coinClick(index)"
            >
              {{info.ChannelName}}
              <template
              >
                <i class="triangle-bottomright"></i>
                <i class="el-icon-check"></i>
              </template>
            </button>
          </div>
        </template>

        <p class="chunk-box-hint">充币地址</p>
        <div class="adress-box">
          <input type="text" class="copy-input" ref="adress" :value="currentAdress" />
          <p>
            <span class="adress-right-text cursor" @click="copyBtn">复制</span>
            <!-- <span >二维码</span> -->
            <el-popover placement="right" width="98" trigger="click" :visible-arrow="false">
              <span class="adress-right-text cursor" slot="reference">二维码</span>
              <canvas class="erwei_img" ref="canvas"></canvas>
            </el-popover>
          </p>
        </div>
      </div>

      <div class="chunk-box-bottom dis-select">
        <p class="chunk-box-bottom-hint">温馨提示</p>
        <ul class="hint-ul">
          <li class="hint-li">为保障资金安全，当您账户安全策略变更、密码修改、我们会对提币进行人工审核，请耐心等待工作人员电话或邮件联系。</li>
          <li class="hint-li">请务必确认电脑及浏览器安全，防止信息被篡改或泄露。</li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
import QRCode from "qrcode";
export default {
  data() {
    return {
      otcCoinList: [
        {
          name: "BTC",
          id: 1
        },
        {
          name: "ETH",
          id: 2
        }
      ], //可用币列表
      coin: "ETH", //当前选择的币
      item: {
        //变量命名为item是为了与之前的保持统一, 空数据为了初始加载的占位
        ServerAddressInfo: [
          { ChannelName: "OMNI" }]
      },
      currentChain: "ERC20", // 当前链
      currentAdress: "0x90A8200d50D8ed99B3dfE038B1430BFa7909d472", // 当前充币地址
      ChannelId: "" // 当前提币id
    };
  },

  methods: {
    /*
     *复制按钮的事件
     */
    copyBtn() {
      let copyText = this.$refs.adress;
      copyText.select(); // 选择对象
      document.execCommand("Copy");
    },
    /*
     *二维码的生成，可选添加变量
     */
    useqrcode(val) {
      if (val) {
        let _this = this;
        _this.QueryDetail = val;
        var canvas = _this.$refs.canvas;
        QRCode.toCanvas(canvas, _this.QueryDetail, function(error) {
          if (error) _this.$message.error("二维码加载错误，请重新尝试");
        });
      }
    },
    /*
     *可用链的点击事件
     */
    coinClick(index) {
      if (this.item.AccountName == "BTC") {
        /*
         *此处对btc进行单独处理，btc没有其它链
         */
        this.ChannelId = 4;
        this.currentAdress = this.item.ServerAddress;
      } else {
        this.currentChain = this.item.ServerAddressInfo[index]
          ? this.item.ServerAddressInfo[index].ChannelName
          : "";
        this.currentAdress = this.item.ServerAddressInfo[index]
          ? this.item.ServerAddressInfo[index].ServerAddress
          : "";
      }
      this.useqrcode(this.currentAdress);
    },
    /*
     *下拉框切换事件
     */
    coinSelectChange(coin) {
      this.reqAdress(coin);
    },
    /*
     *用户充币地址的请求
     */
    reqAdress(coin) {
      let param = {
        CoinType: coin
      };
      this.currentAdress = "0xF73d8f5BFb7f03b0AF375b1b5cF6581C367890e8";
    }
  },

  computed: {},

  created() {},

  mounted() {}
};
</script>
<style scoped>
.hint-text {
  font-size: 12px;
  color: rgba(153, 153, 153, 1);
  line-height: 17px;
}
.box {
  padding: 20px 20px 0 20px;
}

.coin-select {
  width: 622px;
  height: 17px;
  margin: 12px 0 20px 0;
}
.chunk-box {
  margin-bottom: 30px;
}
.chunk-box-hint {
  color: #999999;
  font-size: 12px;
  line-height: 12px;
}
.support-box {
  display: flex;
  margin: 13px 0 20px 0;
}
.coin-btn {
  width: 134px;
  height: 48px;
  border-radius: 4px;
  background-color: #f5f3f9;
  border: solid 1px #eeeeee;
  margin-right: 44px;
  font-size: 14px;
  color: #333333;
  position: relative;
}
.coinIsClick {
  border: solid 1px #54c9c4;
}
.triangle-bottomright {
  width: 0;
  height: 0;
  border-bottom: 28px solid #31c0ce;
  border-left: 28px solid transparent;

  line-height: 28px;
  text-align: center;
  position: absolute;
  right: 0;
  bottom: 0;
}
.el-icon-check {
  color: #fff;
  position: absolute;
  right: 1px;
  bottom: 2px;
  font-weight: bold;
}
.btnDis {
  color: #c4c2c2;
}
.adress-box {
  width: 622px;
  height: 48px;
  margin-top: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: solid 1px #eeeeee;
  padding: 0 21px;
}
.copy-input {
  color: #333333;
  font-size: 16px;
  width: 75%;
  /* height:48px; */
  border: none;
}
.adress-right-text {
  font-size: 14px;
  color: #31c0ce;
  margin-left: 30px;
  display: inline-block;
}
.erwei_img {
  width: 120px !important;
  height: 120px !important;
  margin: 0 auto;
}
.chunk-box-bottom {
  color: #cccccc;
  font-size: 12px;
  letter-spacing: 1px;
}
.chunk-box-bottom-hint {
  margin-bottom: 18px;
}
.hint-ul {
  padding: 0 10px;
}
.hint-li {
  line-height: 16px;
  width: 450px;
  margin: 10px 0px;
  list-style: disc;
}
</style>
